Syntax10.Scn.Fnt StampElems Alloc 16 Jun 95 InfoElems Alloc Syntax10.Scn.Fnt StampElems Alloc 16 Jun 95 "Title": Run time debugger "Author": mah "Abstract": Compiler information grabber "Keywords": "Version": "From": 25.10.94 16:53:38 "Until": "Changes": ParcElems Alloc Syntax10i.Scn.Fnt Syntax10b.Scn.Fnt FoldElems Syntax10.Scn.Fnt Syntax10b.Scn.Fnt pc-: POINTER TO ARRAY OF SHORTINT; pos-: POINTER TO ARRAY OF LONGINT; END; Syntax10.Scn.Fnt Syntax10i.Scn.Fnt name: ARRAY 32 OF CHAR; (* modul name of entry *) mod: Modules.Module; (* modul descriptor *) sym: Sym; (* symbol info of module 'name' *) stat: Stat; (* statements of module 'name' *) END; Syntax10.Scn.Fnt Syntax10i.Scn.Fnt pos, i: INTEGER; indexcheckoff, typecheckoff: BOOLEAN; trap: Modules.TrapDescPtr; BEGIN indexcheckoff := TRUE; typecheckoff := TRUE; pos := 1; o[0] := 'n'; FOR i := 0 TO mod.noftraps-1 DO trap := SYS.VAL (Modules.TrapDescPtr, mod.traps+i*SIZE (Modules.TrapDesc)); CASE trap.trapno OF 1: indexcheckoff := FALSE (* has index check -> no 'x' parameter *) | 4: typecheckoff := FALSE (* has type check -> no 't' parameter *) | 7: pos := 0 (* has NIL check -> no 'n' parameter *) ELSE END END; IF indexcheckoff THEN o[pos] := 'x'; INC (pos) END; IF typecheckoff THEN o[pos] := 't'; INC (pos) END; o[pos] := 'f'; o[pos+1] := CHR(0) (* add findpc option *) END GetOptions; Syntax10.Scn.Fnt BEGIN WHILE (obj # NIL) & (obj.name # name) DO IF name < obj.name THEN obj := obj.left ELSE obj := obj.right END END; RETURN obj END Find; Syntax10.Scn.Fnt VAR cnt: INTEGER; s: OPV.Stats; i: INTEGER; BEGIN s := OPV.stats; cnt := 0; WHILE s # NIL DO INC (cnt, s.numStat); s := s.next END; NEW (stat.pc, cnt); NEW (stat.pos, cnt); s := OPV.stats; cnt := 0; WHILE s # NIL DO FOR i := 0 TO s.numStat-1 DO stat.pc[cnt+i] := s.pc[i]; stat.pos[cnt+i] := s.pos[i]; END; INC (cnt, s.numStat); s := s.next END ConvertStats; Syntax10.Scn.Fnt Syntax10i.Scn.Fnt slot, i: INTEGER; name: ARRAY 36 OF CHAR; source, out: Texts.Text; r: Texts.Reader; option: ARRAY 5 OF CHAR; err: BOOLEAN; BEGIN slot := 0; WHILE (slot # maxnofmods) & (mod.name # modCache[slot].name) DO INC (slot) END; IF slot = maxnofmods THEN slot := nextslot ELSIF modCache[slot].mod = mod THEN RETURN slot END; COPY (mod.name, name); i := 0; WHILE name[i] # 0X DO INC (i) END; name[i] := '.'; name[i+1] := 'M'; name[i+2] := 'o'; name[i+3] := 'd'; name[i+4] := CHR(0); source := TextFrames.Text (name); IF source.len = 0 THEN RETURN -1 END; FoldElems.ExpandAll (source, 0, TRUE); Texts.OpenReader (r, source, 0); out := TextFrames.Text (""); GetOptions (mod, option); Compiler.Module (r, option, 0, out, err); IF (Compiler.mainMod = NIL) OR (OPV.stats = NIL) THEN RETURN -1 END; modCache[slot].mod := mod; modCache[slot].sym := Compiler.mainMod; COPY (mod.name, modCache[slot].name); ConvertStats (modCache[slot].stat); IF slot = nextslot THEN nextslot := (nextslot+1) MOD maxnofmods END; Compiler.mainMod := NIL; (* help garbage collector *) OPV.stats := NIL; RETURN slot END LoadModule; Syntax10.Scn.Fnt VAR i: INTEGER; BEGIN FOR i := 0 TO maxnofmods-1 DO modCache[i].mod := NIL; modCache[i].sym := NIL; modCache[i].stat.pc := NIL; modCache[i].stat.pos := NIL END; nextslot := 0 END Release; Syntax10.Scn.Fnt PROCEDURE Scan (o: Sym); BEGIN IF o # NIL THEN Scan (o.left); proc (o); Scan (o.right) END END Scan; BEGIN Scan (scope) END ScanScope; Syntax10.Scn.Fnt VAR idx: INTEGER; BEGIN idx := LoadModule (Modules.ThisMod (name)); IF idx = -1 THEN stats.pc := NIL ELSE stats := modCache[idx].stat END END Statements; Syntax10.Scn.Fnt VAR idx: INTEGER; BEGIN idx := LoadModule (Modules.ThisMod (name)); IF idx = -1 THEN syms := NIL ELSE syms := modCache[idx].sym END END Symbols; Syntax10.Scn.Fnt Syntax10i.Scn.Fnt VAR sym: Sym; BEGIN Symbols (type.module.name, sym); IF sym = NIL THEN Symbols (module.name, sym) END; (* get info of type as imported in module *) ASSERT (sym # NIL); RETURN Find (sym, type.name) END FindType; MODULE RTDC; (* Run time debugger: Compiler reference & position information; mah 25.10.94 ( IMPORT OPV := POPV, OPT := POPT, Modules, SYS := SYSTEM, Texts, TextFrames, Compiler, Types, FoldElems, RTDT; CONST maxnofmods = 5; (* cache size: max # of modules cached *) Sym* = OPT.Object; (* alias to hide compiler type *) Type* = OPT.Struct; Stat* = RECORD ModuleCache = RECORD ScanProc* = PROCEDURE (obj : Sym); (* iterator type for scanning scopes *) nextslot: INTEGER; (* next slot to be used in cache (round robin) *) modCache: ARRAY maxnofmods OF ModuleCache; (* modul cache *) PROCEDURE GetOptions (mod: Modules.Module; VAR o: ARRAY OF CHAR); PROCEDURE Find (obj: Sym; VAR name: ARRAY OF CHAR) : Sym; PROCEDURE ConvertStats (VAR stat: Stat); PROCEDURE LoadModule (mod: Modules.Module) : INTEGER; PROCEDURE Release*; PROCEDURE ScanScope* (scope: Sym; proc: ScanProc); PROCEDURE Statements* (name: ARRAY OF CHAR; VAR stats: Stat); PROCEDURE Symbols* (name: ARRAY OF CHAR; VAR syms: Sym); PROCEDURE FindType* (type: Types.Type; module: Modules.Module) : Sym; PROCEDURE FindProc* (proc : RTDT.Proc) : Sym; o, parentScope: Sym; parentProc: RTDT.Proc; mod: Modules.Module; i, j: INTEGER; n: ARRAY 64 OF CHAR; BEGIN i := 0; WHILE (proc.name[i] # 0X) & (proc.name[i] # '.') DO INC (i) END; IF proc.name[i] = '.' THEN (* typebound typename.procname *) COPY (proc.name, n); n[i] := 0X; Symbols (proc.modName, o); o := Find (o, n); j := 0; REPEAT n[j] := proc.name[i+1]; INC (i); INC (j) UNTIL proc.name[i] = 0X; IF o.typ.form = 13 THEN o := o.typ.BaseTyp.strobj END; (* pointer as self parameter *) o := Find (o.typ.link, n); RETURN o.scope.right ELSE (* normal or local procedure (takes care of local procedures) *) parentProc := proc.up; WHILE (parentProc # NIL) & (parentProc.modName = proc.modName) DO parentScope := FindProc (parentProc); IF parentScope # NIL THEN o := Find (parentScope, proc.name); IF o#NIL THEN RETURN o.scope.right END END; parentProc := parentProc.up END; Symbols (proc.modName, o); o := Find (o, proc.name); RETURN o.scope.right END FindProc; END RTDC.